package com.party.core.service.collect.impl;

import com.party.common.paging.Page;
import com.party.common.utils.StringUtils;
import com.party.core.dao.read.collect.SystemModuleCollectReadDao;
import com.party.core.dao.write.collect.SystemModuleCollectWriteDao;
import com.party.core.model.BaseModel;
import com.party.core.model.collect.SystemModuleCollect;
import com.party.core.service.collect.ISystemModuleCollectService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @Description:
 * @Author: yangshoukun
 * @Date: 2018/6/20 18:12
 */
@Service
public class SystemModuleCollectService implements ISystemModuleCollectService {

    @Autowired
    private SystemModuleCollectReadDao systemModuleCollectReadDao;

    @Autowired
    private SystemModuleCollectWriteDao systemModuleCollectWriteDao;

    @Override
    public String insert(SystemModuleCollect systemModuleCollect) {
        BaseModel.preInsert(systemModuleCollect);
        boolean result = systemModuleCollectWriteDao.insert(systemModuleCollect);
        if (result){
            return systemModuleCollect.getId();
        }
        return null;
    }

    @Override
    public boolean update(SystemModuleCollect systemModuleCollect) {
        systemModuleCollect.setUpdateDate(new Date());
        return systemModuleCollectWriteDao.update(systemModuleCollect);
    }

    @Override
    public boolean deleteLogic(String id) {
        if (StringUtils.isEmpty(id)) {
            return false;
        }
        return systemModuleCollectWriteDao.deleteLogic(id);
    }

    @Override
    public boolean delete(String id) {
        if (StringUtils.isEmpty(id)) {
            return false;
        }
        return systemModuleCollectWriteDao.delete(id);
    }

    @Override
    public boolean batchDeleteLogic(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return false;
        }
        return systemModuleCollectWriteDao.batchDeleteLogic(ids);
    }

    @Override
    public boolean batchDelete(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return false;
        }
        return systemModuleCollectWriteDao.batchDelete(ids);
    }

    @Override
    public SystemModuleCollect get(String id) {
        return systemModuleCollectReadDao.get(id);
    }

    @Override
    public List<SystemModuleCollect> listPage(SystemModuleCollect systemModuleCollect, Page page) {
        return systemModuleCollectReadDao.listPage(systemModuleCollect, page);
    }

    @Override
    public List<SystemModuleCollect> list(SystemModuleCollect systemModuleCollect) {
        return listPage(systemModuleCollect, null);
    }

    @Override
    public List<SystemModuleCollect> batchList(Set<String> ids, SystemModuleCollect systemModuleCollect, Page page) {
        return null;
    }

    @Override
    public SystemModuleCollect findByModuleAndDate(String module, Date createDate) {
        return systemModuleCollectReadDao.findByModuleAndDate(module, createDate);
    }

    @Override
    public Map<String, Object> findByModuleAndDateRange(String module, String startDate, String endDate) {
        return systemModuleCollectReadDao.findByModuleAndDateRange(module, startDate, endDate);
    }
}
